Skip to content

fix(cli): publish cli/package.json so --cli metadata lookup works from the installed package#1702

Open
n0liu wants to merge 1 commit into
modelcontextprotocol:mainfrom
n0liu:fix/include-cli-package-json-in-files
Open

fix(cli): publish cli/package.json so --cli metadata lookup works from the installed package#1702
n0liu wants to merge 1 commit into
modelcontextprotocol:mainfrom
n0liu:fix/include-cli-package-json-in-files

Conversation

@n0liu

@n0liu n0liu commented Jul 17, 2026

Copy link
Copy Markdown

Summary

The CLI (--cli mode) is broken from v0.17.0 through v0.22.0: invocations can fail immediately with ERR_MODULE_NOT_FOUND for cli/package.json.

cli/build/index.js reads ../package.json to get the CLI name and version for the client identity. The root package files allowlist ships cli/build but not cli/package.json, so that file is absent from the published npm tarball. The current cwd-relative fs.existsSync("../package.json") probe selects the module-relative ../package.json (which resolves to cli/package.json) whenever the process working directory happens to have a sibling package.json, and the dynamic import then fails because the file was never published.

Adding cli/package.json to files makes both resolution targets present in the tarball, so the metadata import always resolves.

This is the packaging half of the problem; #1337 separately hardens the runtime resolution to be module-relative. The two are complementary and touch different files (package.json here vs cli/src/index.ts there).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How verified

npm pack --dry-run at the repo root (lifecycle scripts skipped for the file listing):

  • Before: cli/package.json is absent from the packed file list
  • After: cli/package.json is present in the packed file list

Related

Fixes #1503

…m the installed package

The root package `files` allowlist did not include `cli/package.json`, so it was absent from the published npm tarball. `cli/build/index.js` imports `../package.json` to read the CLI name and version for the client identity; when the process working directory happens to have a sibling `package.json`, the existing cwd-relative `fs.existsSync` probe selects that module-relative `../package.json` (i.e. `cli/package.json`), which is not shipped, and every `--cli` invocation dies with `ERR_MODULE_NOT_FOUND` (broken since v0.17.0).

Adding `cli/package.json` to `files` makes both resolution targets present in the tarball, so the metadata import always succeeds. Verified with `npm pack --dry-run`: the file is absent before this change and present after.

Fixes modelcontextprotocol#1503
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI broken since v0.17.0: ERR_MODULE_NOT_FOUND for cli/package.json

1 participant